<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
<title>现场挂号</title>
</head>
<body>
<article class="page-container">
	<form method="post" class="form form-horizontal" id="frmRegist" name="frmRegist">
	    <!------------------------------HEAD---------------------------->
		<div class="row cl">
		<!------------------------------发票号---------------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>发票号：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text" th:value="${invoice.invoiceNum}" placeholder="" id="invoiceNum" name="invoiceNum">
				<p><span style="color:red;" th:text=${errInvoice}></span></p>
			</div>
			<!------------------------------挂号---------------------------->
			<div class="formControls col-xs-1 col-sm-1">
				<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;挂号&nbsp;&nbsp;" id="btnRegist"  >
			</div>
			<!------------------------------清空---------------------------->
			<div class="formControls col-xs-2 col-sm-2">
				<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;清空&nbsp;&nbsp;" id="btnReset">
			</div>			
			<label class="form-label col-xs-5 col-sm-5"></label>
		</div>
		 <!------------------------------挂号信息：Title---------------------------->
		<div class="row cl">
			  <!-----------------------------病历号---------------------------->
			<label class="form-label col-xs-1 col-sm-1" style="font-size:18px">挂号信息</label>
			  <!-----------------------------看诊日期----------------------------------->
			<label class="form-label col-xs-10 col-sm-11" style="font-size:16px">看诊日期： 
			<span style="font-weight:700">
				<span  th:text="${#dates.format(new java.util.Date().getTime(),'yyyy-MM-dd')}"></span>
				<input type="hidden" id="visitDate" name="visitDate" th:value="${#dates.format(new java.util.Date().getTime(),'yyyy-MM-dd')}" />
				<span id="registNoon" style="margin-left:25px"></span>
				<input type="hidden" id="noon" name="noon" />
			</label>
			<label class="form-label col-xs-11 col-sm-11"></label>
			</span>
		</div>
		<hr>
		 <!------------------------------挂号信息：第1行---------------------------->
		<div class="row cl">
		  <!-----------------------------病历号---------------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>病历号：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text" th:value="${regist.caseNumber}==null?${caseNumber}:${regist.caseNumber}" placeholder="" id="caseNumber" name="caseNumber">
			</div>
			<!------------------------------病历查询---------------------------->
			<div class="formControls col-xs-2 col-sm-2">
				<input class="btn btn-primary radius" type="submit" name="btnQuery"
					   id="btnQuery" value="&nbsp;&nbsp;病例查询&nbsp;&nbsp;">
			</div>
			<label class="form-label col-xs-11 col-sm-11"></label>
		</div>	
		 <!------------------------------挂号信息：第2行---------------------------->
		<div class="row cl">
		  <!------------------------------姓名---------------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>姓名：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text" class="input-text"  id="realName"
				        name="realName" th:value="${regist.realName}">
			</div>
			<!------------------------------性别---------------------------->	 
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>性别：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<div class="radio-box">
					<input type="radio" name="gender" id="sex71" value="71" th:checked="${regist.gender==71}">
					<label for="sex71" style="margin-right:25px">男</label>
					<input type="radio" name="gender" id="sex72" value="72" th:checked="${regist.gender==72}">
					<label for="sex72">女</label>
				</div>
			</div>
			<!------------------------------出生日期---------------------------->	 
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>出生日期：</label>
			<div class="formControls col-xs-2 col-sm-2">
				<input type="text"  class="input-text Wdate" autocomplete="off"
				       id="birthday" name="birthDate"
					   th:value="${#dates.format(regist.birthDate,'yyyy-MM-dd')}"
					   onchange="setAgeByBirthday(this.value)"
					   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})">
			</div>
			   <!------------------------------年龄---------------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>年龄：</label>
			<div class="formControls col-xs-1 col-sm-1">
				<input type="text" class="input-text" th:value="${regist.age==0?'':regist.age}"
				  id="age" name="age">
			</div>
			  <!------------------------------年龄单位---------------------------->
			<div class="formControls col-xs-1 col-sm-1">	
				<span class="select-box">
				<select class="select" size="1" name="ageType" id="ageType">
					<option value="岁" th:selected="${regist.ageType=='岁'}">岁</option>
					<option value="月" th:selected="${regist.ageType=='月'}">月</option>
					<option value="日" th:selected="${regist.ageType=='日'}">日</option>
				</select>
				</span>
			</div>
			<label class="form-label col-xs-11 col-sm-11"></label>
		</div>
			 <!------------------------------挂号信息：第3行---------------------------->
		<div class="row cl">
		       <!------------------------------挂号级别---------------------------->		
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>挂号级别</label>
			<div class="formControls col-xs-2 col-sm-2">			
				<span class="select-box">
				<select class="select" size="1" name="registLeID">
					<option value="" selected>请选择挂号级别</option>
					<option th:each="registlevel:${levelList}"
						th:value="${registlevel.iD}"
						th:text="${registlevel.registName}"
						th:selected="${registlevel.iD == regist.registLeID}">  
					</option>
					
				</select>
				</span>
				<p>
				    <span style="color:red;" th:text="${errRegistLevel}">
				</p>
			</div>
			 <!------------------------------挂号科室---------------------------->
			<label class="form-label col-xs-1 col-sm-1"><span class="c-red">*</span>挂号科室</label>
			<div class="formControls col-xs-2 col-sm-2">
			
				<input type="text" class="input-text" id="dept"
					   name="deptName" th:value="${regist.deptName} "/>
				<input type="hidden" name="deptID" th:value="${regist.deptID}"/>
				<div id="dropdown" class="ac_results"></div>
			</div>
			 <!------------------------------医生查询---------------------------->
			<div class="formControls col-xs-1 col-sm-1">
				<input id="btnQueryScheduling" class="btn btn-primary radius" 
				type="button" value="&nbsp;&nbsp;医生查询&nbsp;&nbsp;">
			</div>
			<label class="form-label col-xs-11 col-sm-11"></label>
		</div>
		<div class="page-container">
			<div class="mt-20">
			<!-- ------------------Table--------------------- -->
			<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<!------------------------- Thead ---------------------------->
				<thead>
					<tr class="text-c">
						<th width="120">选择</th>
						<th width="150">排班日期</th>
						<th width="120">午别</th>
						<th width="120">真实姓名</th>
						<th width="120">医生职称</th>
						<th width="150">所在科室</th>
						<th width="150">挂号级别</th>
					</tr>
				</thead>
				<!------------------------- Tbody ---------------------------->
				<tbody>
					<tr class="text-c" th:each="scheduling,status:${schedulingList}" onclick="setFouce(this)"> 
					<td style="padding:0">
					   <input type="radio"  name="userID"
					      th:value="${scheduling.user.id}" 
					      th:checked="${status.first}">
					</td>
					<td th:text="${#dates.format(scheduling.schedDate,'yyyy-MM-dd')}"></td>
					<td th:text="${scheduling.noon}"></td>
					<td class="text-l" th:text="${scheduling.user.realName}"></td>
					<td th:text="${scheduling.user.constantName}"></td>
					<td th:text="${scheduling.user.deptName}"></td>
					<td th:text="${scheduling.user.registName}"></td>									
				</tr>
				</tbody>
			</table>
			</div>	
		</div>				
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<script type="text/javascript" src="/ext/selectCity/dept.js"></script> 
<script type="text/javascript" src="/ext/selectCity/dimensions.js"></script> 
<script type="text/javascript" src="/ext/selectCity/suggest.js"></script> 
<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/lib/datatables/1.10.15/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">

$('.table-sort').dataTable({
	"lengthMenu":[5,10,15], //表格左上角下拉框长度
	"aaSorting": [ [ 1, "desc" ] ], //默认第几列排序
	"bStateSave": true, //状态保存
	"paging":true, //是否分页
	"searching":true
});
//病例查询按钮点击事件
$('#btnQuery').click(function(){
	//移除校验规则
	$("#realName").rules("remove","required");
	$("#age").rules("remove","required");
	$("#dept").rules("remove","required");
	
	$('#frmRegist').attr("action","/rg/caseInfo");
	$('#frmRegist').submit();
	
});
//医生排班列表查询按钮点击事件
$('#btnQueryScheduling').click(function(){
	$("#realName").rules("remove","required");
	$("#age").rules("remove","required");
	$("#dept").rules("remove","required");

	$('#frmRegist').attr("action","/rg/schedulingInfo");
	$('#frmRegist').submit();
});
//按年龄设置出生日期
$('age').change(function(){
	setBirthdayByAge(this.value);
});
//按年龄类别，设置出生日期
$('ageType').change(function(){
	setBirthdayByAge($('#age').val());
});

//挂号按钮,点击事件
$('#btnRegist').click(function(){
	//增加校验规则
	$("#realName").rules("add",{required:true});
	$("#age").rules("add",{required:true});
	$("#dept").rules("add",{required:true});
	
	$('#frmRegist').attr('action','/rg/doRegist');
	$('#frmRegist').submit();		
});
//清空按钮点击事件
$('#btnReset').click(function(){
	window.location.replace('/rg/regist');
});
//调用挂号科室下拉菜单事件
$(function(){
	$("#dept").suggest(citys,{
		hot_list:commoncitys
	});
});



$(function(){	
	$("#registNoon").html(amPm(new Date()));
	$("#noon").val(amPm(new Date()));
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#frmRegist").validate({
		rules:{
			age:{
				required:true
			},
			realName:{
				required:true,
				minlength:2,
				maxlength:16
			},
			dept:{ }
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid"
	});
	
});
function amPm(date){
	return date.getHours() > 12 ? '下午' : '上午' ;
}
//年 月 日 毫秒数
var millYear=1000*60*60*24*365;
var millMonth=1000*60*60*24*30;
var millDate=1000*60*60*24;
//根据年龄设置出生日期
function setAgeByBirthday(txtValue){
	var value="";
	var type="岁";
	//生日日期
	if(txtValue!=''){
		var ymd=txtValue.split('-');
		var birthday =new Date(ymd[0],ymd[1]-1,ymd[2]);
	
	//当前日期
	var now=new Date();
	now=new Date(now.getFullYear(),now.getMonth(),now.getDate());
	
	//计算年龄
	var milliseconds=now.getTime()-birthday.getTime();
	value=parseInt(milliseconds/millYear);
	if(value<1){
		    value=parseInt(milliseconds/millMonth);
		if(value<1){
			value=parseInt(milliseconds/millDate);
			type="日";
		}else{
			type="月";
		}
		}else{
			type="岁";
		}
	  }
	$('#age').val(value);
	$('#ageType').val(type);	

}
//根据年龄设置出生日期
function setBirthdayByAge(txtValue){
	var millNow =new Date().getTime();
	
	var type =$('#ageType').val();
	if(type=='岁'){
		milliseconds=millNow -txtValue*millYear;
	}else if(type=='月'){
		milliseconds=millNow -txtValue*millMonth;
	}else{
		milliseconds=millNow -txtValue*millDate;
	}
	$('#birthday').val(dateFormat('yyyy-mm-dd',new Date(milliseconds)));
}
//用JS方式格式化日期
function dateFormat(fmt,date){
	let ret;
	const opt={
			"y+":date.getFullYear().toString(),//年
			"m+":(date.getMonth()+1).toString(),//月
			"d+":date.getDate().toString(),//日
			"H+":date.getHours().toString(),//时
			"M+":date.getMinutes().toString(),//分
			"S+":date.getSeconds().toString(),//秒
	};
	for( let k in opt){
		ret =new RegExp("("+ k +")").exec(fmt);
		if(ret){
			fmt=fmt.replace(ret[1],(ret[1].length==1)?(opt[k])
					:(opt[k].padStart(ret[1].length,"0")));
		}
	}
	return fmt;
}
//点击行，当前行的radio获得焦点
function setFouce(node){
	var $chk =$(node).children().first().children()  //node  dom对象--->$(node)数组jquery-->$(node).children()该行所有td-->$(node).children().first().children()第一个td里的input
	$chk.prop('checked',!$chk.prop('checked'))
/* 	$(node).children.children().first.prop('checked',true);
 */}
</script> 
</body>
</html>
